package sing.core

import android.content.Context
import android.os.Build
import android.os.Environment
import java.io.File

object Global {

    var channel = "" // 渠道，在 MyApp 中初始化
    var H5_URL = "https://api.rentianjf.com"

    fun getImageFilePath() : String{
        val externalDataDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)
        return "$externalDataDir"
    }

    fun getImageFile() : String{
        val externalDataDir = getImageFilePath()
        return "${externalDataDir}${File.separator}${System.currentTimeMillis()}.png"
    }

    fun getDownloadPath() : String{
        val externalDataDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
        return "${externalDataDir}${File.separator}"
    }


    fun getImageAppPath(context: Context) : String{
        val file = File(Global.getAppPath(context),"image")
        if (!file.exists()) {
            file.mkdir()
        }
        return file.path
    }

    fun getAppPath(context: Context) : String{
        if (Build.VERSION.SDK_INT >= 29) {
            return "${context.getExternalFilesDir(null)?.absolutePath}${File.separator}"
        }else{
            return "${Environment.getExternalStorageDirectory().path}${File.separator}"
        }
    }
}